package dao

import (
	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
	"time"
)

type Log struct {
	Id        int64     `json:"id" gorm:"column:id;comment:自增id"`
	Key       string    `json:"key" gorm:"column:key;comment:行为;index;"`
	CreatedBy string    `json:"created_by" gorm:"column:created_by;comment:创建人"`
	Status    uint8     `json:"status" gorm:"column:status;comment:状态"`
	IsDelete  uint8     `json:"is_delete" gorm:"column:is_delete;comment:1已删除"`
	UpdatedAt time.Time `json:"update_at" gorm:"column:update_at;comment:更新时间"`
	CreatedAt time.Time `json:"create_at" gorm:"column:create_at;comment:创建时间"`
}

func (f *Log) TableName() string {
	return "log"
}

// InitData 初始化menu表
func (f *Log) InitData(tx *gorm.DB) error {
	return tx.AutoMigrate(f)
}

// Save 保存
func (f *Log) Save(c *gin.Context, tx *gorm.DB) error {
	if err := tx.WithContext(c).Save(f).Error; err != nil {
		return err
	}
	return nil
}
